package service;

import Dao.IUserDao;
import Dao.UserDaoImpl;
import user.entity.User;

import java.util.List;
//对Dao层进行拼接，实现独立功能
public class UserServiceImpl implements UserService {
    IUserDao userDao=new UserDaoImpl();
    @Override
    public boolean addUser(User user) {
        if(userDao.IsExist(user.getNum()))
        {
            return userDao.addUser(user);
        }
        else        //此人已存在
        return false;
    }

    @Override
    public boolean deleteUser(String num) {
        if(!userDao.IsExist(num))
            return userDao.deleteUser(num);
        else        //不存在
        return false;
    }

    @Override
    public boolean updateUser(String num, User user) {
        if(!userDao.IsExist(num))
            return userDao.updateUser(num,user);
       else return false;
    }

    @Override
    public List<User> queryAll() {
        return userDao.queryAllUser();
    }

    @Override
    public User queryByNum(String num) {
        if(!userDao.IsExist(num))
            return userDao.queryByNum(num);
        else
        return null;
    }

    @Override
    public List<User> queryByName(String name) {
            return userDao.queryByName(name);
    }

    @Override
    public List<User> queryByGrade(String grade) {
            return userDao.queryByGrade(grade);
    }
}
